/*
 * This Program creates a list of prime numbers that are lower than specified one
 */
import java.util.*;
public class ListOfPrimeNumbers{
	public static void main(String[] args){
		// Initialize input from keyboard
		Scanner in = new Scanner(System.in);
		
		// Initialize specified number. If number is not positive input is repeated.
		int number = 0;
		while (number <= 0){
		System.out.println("Input any integer");
		number = in.nextInt();
		if (number <= 0) System.out.println("You should input positive integer");
		}
		
		// Initialize array that will hold all prime numbers
		int[] listOfPrimes;
		// Inintialize variable that holds the state of number(prime or not)
		boolean isPrime = true;
		
		// Build list of Primes for numers 1 and 2
		if (number < 2) {
			listOfPrimes = new int[] {1};
		}
		else{ 
			listOfPrimes = new int[] {1,2};
		}
		
		// Search for prime numbers that are lower than specified one
		for (int potentialPrime = 3; potentialPrime <= number; potentialPrime += 2){
			isPrime = true;
			for (int i =1; i < listOfPrimes.length; i++){
				int remain = potentialPrime % listOfPrimes[i];
				if ( remain == 0){ 
				isPrime = false;
				break;
				}
			}
			if (isPrime){
				listOfPrimes = Arrays.copyOf(listOfPrimes, listOfPrimes.length+1);
				listOfPrimes[listOfPrimes.length - 1] = potentialPrime;
			}
		}
		
		// Output all prime numbers
		System.out.printf("The prime numbers less than %d are: \n", number);
		for(int i =0; i < listOfPrimes.length; i++)
			System.out.print(listOfPrimes[i]+" ");		
	}
}